package com.iostream;

import java.io.*;

/**
 * @Author WaveHi
 * @Date 20/8/2021 下午 5:26
 * @Version 1.0
 * @Contact HJBWaveHi@163.com
 * @Description Test the use of java.io.
 */
public class TestBufferedReaderWriter {

    public static void main(String[] args) {
        BufferedReader br1 = null;
        BufferedWriter bw1 = null;

        try {
            //获取存取数据的位置
            File srcFile1 = new File("day11/txt/hello.txt");
            File destFile1 = new File("day11/txt/hello7.txt");

            //获取需存取的数据
            //获取流
            FileReader fr1 = new FileReader(srcFile1);
            FileWriter fw1 = new FileWriter(destFile1);
            br1 = new BufferedReader(fr1);
            bw1 = new BufferedWriter(fw1);

            //接收存取的数据
            char[] cbuf = new char[10];

            //获取存取数据的长度
            int len = 0;

            //存取数据
            while((len = br1.read(cbuf)) != -1) {

                bw1.write(cbuf,0,len);

            }
            System.out.println("Data transfer completed!");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            //资源的关闭
            if(br1 != null) {

                try {
                    br1.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
            if(bw1 != null) {

                try {
                    bw1.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }

            }
        }


    }

}
